/
IProducerEndpointBuilder`1.cs
156 lines (145 loc) · 6.26 KB
/
IProducerEndpointBuilder`1.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
// Copyright (c) 2020 Sergio Aquilini
// This code is licensed under MIT license (see LICENSE file for details)
using System;
using Silverback.Messaging.Encryption;
using Silverback.Messaging.Messages;
using Silverback.Messaging.Outbound;
using Silverback.Messaging.Outbound.TransactionalOutbox;
using Silverback.Messaging.Serialization;
namespace Silverback.Messaging.Configuration
{
/// <summary>
/// Builds the <see cref="ProducerEndpoint" />.
/// </summary>
/// <typeparam name="TBuilder">
/// The actual builder type.
/// </typeparam>
public interface IProducerEndpointBuilder<out TBuilder> : IEndpointBuilder<TBuilder>
where TBuilder : IProducerEndpointBuilder<TBuilder>
{
/// <summary>
/// Specifies the <see cref="IMessageSerializer" /> to be used to serialize the messages.
/// </summary>
/// <param name="serializer">
/// The <see cref="IMessageSerializer" />.
/// </param>
/// <returns>
/// The endpoint builder so that additional calls can be chained.
/// </returns>
TBuilder SerializeUsing(IMessageSerializer serializer);
/// <summary>
/// Specifies the <see cref="EncryptionSettings" /> to be used to encrypt the messages.
/// </summary>
/// <param name="encryptionSettings">
/// The <see cref="EncryptionSettings" />.
/// </param>
/// <returns>
/// The endpoint builder so that additional calls can be chained.
/// </returns>
TBuilder Encrypt(EncryptionSettings encryptionSettings);
/// <summary>
/// Specifies the strategy to be used to produce the messages.
/// </summary>
/// <param name="strategy">
/// The <see cref="IProduceStrategy" />.
/// </param>
/// <returns>
/// The endpoint builder so that additional calls can be chained.
/// </returns>
TBuilder UseStrategy(IProduceStrategy strategy);
/// <summary>
/// Specifies that the <see cref="DefaultProduceStrategy" /> has to be used, producing directly to the
/// message broker.
/// </summary>
/// <returns>
/// The endpoint builder so that additional calls can be chained.
/// </returns>
TBuilder ProduceDirectly();
/// <summary>
/// Specifies that the<see cref="OutboxProduceStrategy" /> has to be used, storing the messages into the
/// transactional outbox table. The operation is therefore included in the database transaction applying
/// the message side effects to the local database. The <see cref="IOutboxWorker" /> takes care of
/// asynchronously sending the messages to the message broker.
/// </summary>
/// <returns>
/// The endpoint builder so that additional calls can be chained.
/// </returns>
TBuilder ProduceToOutbox();
/// <summary>
/// Enables chunking, splitting the larger messages into smaller chunks.
/// </summary>
/// <param name="chunkSize">
/// The maximum chunk size in bytes.
/// </param>
/// <param name="alwaysAddHeaders">
/// A value indicating whether the <c>x-chunk-index</c> and related headers have to be added to the
/// produced message in any case, even if its size doesn't exceed the single chunk size. The default is
/// <c>true</c>.
/// </param>
/// <returns>
/// The endpoint builder so that additional calls can be chained.
/// </returns>
TBuilder EnableChunking(int chunkSize, bool alwaysAddHeaders = true);
/// <summary>
/// Adds the specified header to all produced messages.
/// </summary>
/// <param name="name">
/// The header name.
/// </param>
/// <param name="value">
/// The header value.
/// </param>
/// <returns>
/// The endpoint builder so that additional calls can be chained.
/// </returns>
TBuilder AddHeader(string name, object? value);
/// <summary>
/// Adds the specified header to all produced messages of the specified type.
/// </summary>
/// <typeparam name="TMessage">
/// The type of the messages to be enriched with this header.
/// </typeparam>
/// <param name="name">
/// The header name.
/// </param>
/// <param name="value">
/// The header value.
/// </param>
/// <returns>
/// The endpoint builder so that additional calls can be chained.
/// </returns>
TBuilder AddHeader<TMessage>(string name, object? value)
where TMessage : class;
/// <summary>
/// Adds the specified header to all produced messages of the specified type, using a value provider function to determine the header value for each message.
/// </summary>
/// <typeparam name="TMessage">
/// The type of the messages to be enriched with this header.
/// </typeparam>
/// <param name="name">
/// The header name.
/// </param>
/// <param name="valueProvider">
/// The value provider function.
/// </param>
/// <returns>
/// The endpoint builder so that additional calls can be chained.
/// </returns>
TBuilder AddHeader<TMessage>(string name, Func<IOutboundEnvelope<TMessage>, object?> valueProvider)
where TMessage : class;
/// <summary>
/// Uses the specified value provider function to set the message id header for each produced message.
/// </summary>
/// <typeparam name="TMessage">
/// The type of the messages to be enriched with this header.
/// </typeparam>
/// <param name="valueProvider">
/// The value provider function.
/// </param>
/// <returns>
/// The endpoint builder so that additional calls can be chained.
/// </returns>
TBuilder WithMessageId<TMessage>(Func<IOutboundEnvelope<TMessage>, object?> valueProvider)
where TMessage : class;
}
}